package com.taotao.service;

import com.taotao.common.pojo.TreeNode;
import com.taotao.dao.ItemCateMapper;
import com.taotao.model.ItemCate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * ItemCateServiceImpl
 * Created by heqianqian on 2017/7/6.
 */
@Service
public class ItemCateServiceImpl implements ItemCateService {

    @Resource
    private ItemCateMapper itemCateMapper;

    @Override
    public List<TreeNode> listItemCate(Long parentId) {
        List<ItemCate> itemCates = itemCateMapper.selectByParentId(parentId);
        List<TreeNode> nodes = new ArrayList<>();
        for (ItemCate itemCate : itemCates) {
            TreeNode treeNode = new TreeNode(itemCate.getId(), itemCate.getName(), itemCate.getIsParent() ? "closed" : "open");
            nodes.add(treeNode);
        }
        return nodes;
    }
}
